import { TaskListPanel } from "./TaskListPanel";
import { ModuleBg } from "../common/ModuleBg";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GTextArea } from "../../../../com/mui/controls/GTextArea";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ObjCreate } from "../common/ObjCreate";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { TaskProcessPanel } from "./imgtxt/TaskProcessPanel";
import { TaskRwardPanel } from "./TaskRwardPanel";
import { DataEvent } from "../../events/DataEvent";
import { TaskInfo } from "../../model/TaskInfo";
import { EventName } from "../../mvc/EventName";
import { ETaskType } from "../../../../Message/Game/ETaskType";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { ECopyType } from "../../../../Message/Public/ECopyType";
import { TaskUtil } from "./TaskUtil";
import { TaskTargetType } from "./imgtxt/TaskTargetType";
import { _selectedTask } from "../../../../this/_selectedTask";
type int = number;
//class TaskInfoPanel
    
    export  class TaskInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._taskListPanel = new TaskListPanel();
            this._taskListPanel.x = 20;
            this._taskListPanel.y = 62;
            addChild(this._taskListPanel);
            this._taskListPanel.addEventListener("task_tree_selected", this.onTaskSelected);
            this._bg = new ModuleBg();
            this.createDes();
            this.createCondition();
            this.createAward();
            this._bg.x = 186;
            this._bg.y = 64;
            addChild(this._bg);
            LoaderHelp.addResCallBack(ResFileConst.task, this.onTaskResLoadedHandler);
            return;
        }

        protected onTaskResLoadedHandler(): void
        {
            this._bg.addItem(GlobalClass.getBitmap(ImagesConst.Task_Des), {"x": 5, "y": 0});
            this._bg.addItem(GlobalClass.getBitmap(ImagesConst.Task_Award), {"x": 5, "y": 203});
            return;
        }

        public get taskId(): int
        {
            if (this._selectedTask) 
            {
                return this._selectedTask.sTask.code;
            }
            return 0;
        }

        public initTaskList(arg1: Array<any>): void
        {
            this._taskListPanel.initTaskList(arg1);
            return;
        }

        public addTask(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg1;
            for(loc1 of loc3) 
            {
                this._taskListPanel.insertTask(loc1);
            }
            return;
        }

        public delTask(arg1: int): void
        {
            this._taskListPanel.delTask(arg1);
            if (this._selectedTask && arg1 == this._selectedTask.sTask.code) 
            {
                this._selectedTask = null;
                this._taskDesTxt.htmlText = "";
                this._taskConditionTxt.htmlText = "";
                this._taskConditionImg.dispose();
                this._taskAwardPanel.updateData(null);
            }
            return;
        }

        public updateTask(arg1: Array<any>): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=arg1;
            for(loc1 of loc3) 
            {
                this._taskListPanel.updateTask(loc1);
                if (!(this._selectedTask && this._selectedTask.sTask.code == loc1.sTask.code)) 
                {
                    continue;
                }
                this._taskConditionTxt.htmlText = HTMLUtil.addColor(this._selectedTask.processStr, "#b1efff");
                this._taskConditionImg.updateData(this._taskConditionTxt, loc1);
            }
            return;
        }

        protected createDes(): void
        {
            this._bg.addItem(ResouceConst.getScaleBitmap("WindowCenterB"), {"x": 2, "y": 25, "width": 356, "height": 72});
            this._taskDesTxt = new GTextArea();
            this._taskDesTxt.styleName = "GTextArea";
            this._taskDesTxt.wordWrap = true;
            this._taskDesTxt.textField.defaultTextFormat = new GTextFormat(FontUtil.songtiName, 12, 11661311, null, null, null, null, null, flash.text.TextFormatAlign.LEFT, null, null, null, 4);
            this._taskDesTxt.textField.selectable = false;
            this._taskDesTxt.editable = false;
            this._taskDesTxt.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._taskDesTxt.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._bg.addItem(this._taskDesTxt, {"x": 12, "y": 25, "width": 344, "height": 70});
            this._taskDesTxt.addEventListener(flash.events.TextEvent.LINK, this.onDesLinkClick);
            return;
        }

        protected createCondition(): void
        {
            this._bg.addItem(ResouceConst.getScaleBitmap("WindowCenterB"), {"x": 2, "y": 126, "width": 356, "height": 72});
            this._taskConditionTxt = ObjCreate.createTextField("", 0, 0, -1, -1, null, GlobalStyle.getTextFormatDefaultFont(GlobalStyle.textFormat1));
            this._taskConditionTxt.textColor = 11661311;
            this._taskConditionTxt.selectable = false;
            this._taskConditionTxt.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._taskConditionTxt.multiline = true;
            this._taskConditionTxt.wordWrap = true;
            this._taskConditionTxt.mouseWheelEnabled = false;
            this._bg.addItem(this._taskConditionTxt, {"x": 12, "y": 132, "width": 344});
            this._taskConditionImg = new TaskProcessPanel();
            this._bg.addItem(this._taskConditionImg, {"x": 0, "y": 0});
            return;
        }

        protected createAward(): void
        {
            this._bg.addItem(ResouceConst.getScaleBitmap("WindowCenterB"), {"x": 2, "y": 228, "width": 356, "height": 72});
            this._taskAwardPanel = new TaskRwardPanel();
            this._bg.addItem(this._taskAwardPanel, {"x": 12, "y": 237});
            return;
        }

        protected onTaskSelected(arg1: DataEvent): void
        {
            var loc1=arg1.data as TaskInfo;
            if (this._selectedTask && this._selectedTask.sTask && loc1.sTask.code == this._selectedTask.sTask.code) 
            {
                return;
            }
            this._selectedTask = loc1;
            this._taskDesTxt.htmlText = HTMLUtil.addColor(loc1.des, "#b1efff");
            this._taskConditionTxt.htmlText = HTMLUtil.addColor(this._selectedTask.processStr, "#b1efff");
            this._taskAwardPanel.updateData(this._selectedTask);
            this._taskConditionImg.updateData(this._taskConditionTxt, loc1);
            dispatchEvent(new DataEvent(EventName.TaskSelected, loc1));
            return;
        }

        protected onDesLinkClick(arg1: Object /* flash.events.TextEvent */): void
        {
            if (!(this._selectedTask == null) && this._selectedTask.sTask.type == ETaskType._ETaskTypeFightSpirit && arg1.text == EventName.FightSpiritGuideDoingEvent) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.FightSpiritShowModule));
                return;
            }
            if (arg1.text == EventName.SpiritEquipGuildEnterCopy) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.GuildOpenCopyWindow, ECopyType._ECopyGuildElite));
                return;
            }
            var loc1=int(arg1.text);
            var loc2=TaskUtil.getTaskTargetInfo(this._selectedTask, loc1, true);
            if (loc2 == TaskTargetType.CrossTaskModule) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossTaskShowModule));
                return;
            }
            if (loc2 != null) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.TaskAutoPathReq, {"target": loc2, "task": _selectedTask}));
            }
            return;
        }

        public show(): void
        {
            this._taskListPanel.show();
            return;
        }

        public dispose(): void
        {
            this._taskAwardPanel.dispose();
            return;
        }

        public get selectedTask(): TaskInfo
        {
            return this._selectedTask;
        }

        protected /* var */_selectedTask: TaskInfo;

        protected /* var */_bg: ModuleBg;

        protected /* var */_taskListPanel: TaskListPanel;

        protected /* var */_taskDesTxt: GTextArea;

        protected /* var */_taskConditionTxt: Object /* flash.text.TextField */;

        protected /* var */_taskAwardPanel: TaskRwardPanel;

        protected /* var */_taskConditionImg: TaskProcessPanel;
    }
